package com.sunxd.vue.domain.service;

import com.sunxd.vue.bean.request.InteractiveActivityQueryRequest;
import com.sunxd.vue.bean.request.InteractiveActivityRequest;
import com.sunxd.vue.bean.response.InteractiveActivityInfo;
import com.sunxd.vue.domain.bean.assembler.InteractiveActivityAssembler;
import com.sunxd.vue.domain.bean.domain.interactive.InteractiveActivity;
import com.sunxd.vue.domain.repository.InteractiveActivityRepository;
import com.sunxd.vue.infrastructure.adapter.db.base.Paging;
import com.sunxd.vue.infrastructure.utils.BeanMapUtil;
import com.sunxd.vue.infrastructure.utils.PagingUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author sun.xd
 * @description: description
 * @date 2024/4/25 12:13
 */
@Service
@RequiredArgsConstructor
public class InteractiveActivityService {

    private final InteractiveActivityRepository repository;

    public Boolean create(InteractiveActivityRequest request) {
        return repository.create(InteractiveActivityAssembler.CONVERTER.req2do(request));
    }


    public Boolean update(InteractiveActivityRequest request) {
        return repository.update(InteractiveActivityAssembler.CONVERTER.req2do(request));
    }


    public InteractiveActivityInfo detail(InteractiveActivityRequest request) {
        InteractiveActivity detail = repository.detail(InteractiveActivityAssembler.CONVERTER.req2do(request));
        return InteractiveActivityAssembler.CONVERTER.do2info(detail);
    }

    public Paging<InteractiveActivityInfo> page(InteractiveActivityQueryRequest request) {
        Map<String, Object> map = BeanMapUtil.beanToMap(request);
        PagingUtil.addPageParam(map, request);
        Paging<InteractiveActivity> page = repository.page(map);
        return PagingUtil.toPaging(page, InteractiveActivityAssembler.CONVERTER::do2info);
    }
}
